import { ServerOptions } from "vite"

type ProxyType = {
    [key: string]: {
        target: string,
        changeOrigin?: boolean,
        rewrite?: (path: string) => string,
        secure?: boolean
    }
}

const TARGET = 'http://10.139.106.28:8082'

const SERVICES = [
	'api-auth',				'api-common',		'api-base',         'api-file'
    // 'api-vat',          'api-base',         'api-option',       'api-gateway',
    // 'api-report',       'api-finance',      'api-enter',        'api-doc',
    // 'api-receipt',      'api-file',         'api-asset',        'api-cit',
    // 'api-carry',        'api-output',       'api-risk',         'api-other',
    // 'api-stat',         'api-transaction',  'api-activiti'
]

// 设置所有的代理
const proxy: ProxyType = SERVICES.reduce( (allProxy: ProxyType, it: string) => {
    allProxy[`/${ it }`] = {
        target: TARGET,
        secure: false
    }

    return allProxy
}, {} )


// 关于前端启动项目的服务器配置
export const SERVE_CONF: ServerOptions = {
    // 监听的ip地址
    host: 'localhost',
    // 端口
    port: 5176,
    // 端口被占用时，尝试下一个可用端口
    strictPort: false,
    // 是否启用https
    https: false,
    // 是否在浏览器中打开页面
    open: false,
    // 代理
    proxy
}
